package com.sdhs.web.controller.workbench;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sdhs.common.annotation.Log;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.poi.ExcelUtil;
import com.sdhs.system.domain.dto.MessageInfoReadDTO;
import com.sdhs.system.domain.vo.MessageInfoReadVO;
import com.sdhs.system.service.IMessageInfoReadService;

/**
 * 消息阅读记录Controller
 *
 * @author mz
 * @date 2023-09-11
 */
@RestController
@RequestMapping("/message/read")
public class MessageInfoReadController extends BaseController {
    @Autowired
    private IMessageInfoReadService messageInfoReadService;


    /**
     * 查询消息阅读记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MessageInfoReadDTO messageInfoReadDTO) {
        startPage();
        List<MessageInfoReadVO> list = messageInfoReadService.selectMessageInfoReadList(messageInfoReadDTO);
        return getDataTable(list);
    }

    /**
     * 导出消息阅读记录列表
     */
    @Log(title = "消息阅读记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MessageInfoReadDTO messageInfoReadDTO) {
        List<MessageInfoReadVO> list = messageInfoReadService.selectMessageInfoReadList(messageInfoReadDTO);
        ExcelUtil<MessageInfoReadVO> util = new ExcelUtil<MessageInfoReadVO>(MessageInfoReadVO. class);
        util.exportExcel(response, list, "消息阅读记录数据");
    }

    /**
     * 获取消息阅读记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(messageInfoReadService.selectMessageInfoReadById(id));
    }

    /**
     * 新增消息阅读记录
     */
    @Log(title = "新增消息阅读记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MessageInfoReadDTO messageInfoReadDTO) {
        return toAjax(messageInfoReadService.insertMessageInfoRead(messageInfoReadDTO));
    }

    /**
     * 修改消息阅读记录
     */
    @Log(title = "修改消息阅读记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MessageInfoReadDTO messageInfoReadDTO) {
        return toAjax(messageInfoReadService.updateMessageInfoRead(messageInfoReadDTO));
    }

    /**
     * 删除消息阅读记录
     */
    @Log(title = "删除消息阅读记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(messageInfoReadService.deleteMessageInfoReadByIds(ids));
    }
}
